
const access_token_name = "access_token";

const captcha_token_name = "captcha_token";

/**
 * 设置接口访问token
 * @param assessToken
 */
export function setAccessToken(assessToken) {
    window.localStorage.setItem(access_token_name,assessToken);
}

/**
 * 获取接口访问token
 * @returns {string}
 */
export function getAccessToken() {
    return window.localStorage.getItem(access_token_name);
}

/**
 * 移除接口访问token
 */
export function removeAccessToken() {
    window.localStorage.removeItem(access_token_name)
}

/**
 * 设置验证码token
 * @param captchaToken
 */
export function setCaptchaToken(captchaToken) {
    window.localStorage.setItem(captcha_token_name,captchaToken);
}

/**
 * 获取验证码token
 * @returns {string}
 */
export function getCaptchaToken() {
    return window.localStorage.getItem(captcha_token_name);
}

/**
 * 移除验证码token
 */
export function removeCaptchaToken() {
    window.localStorage.removeItem(captcha_token_name)
}

/**
 * 写入用户信息
 * @param info
 */
export function writeUserInfo(info) {
    window.localStorage.setItem("username",info["username"]);
    window.localStorage.setItem("nickname",info["nickname"]);
    window.localStorage.setItem("pic",info["pic"]);
    window.localStorage.setItem("email",info["email"]);
}

/**
 * 移除用户信息
 */
export function removeUserInfo() {
    window.localStorage.removeItem("username");
    window.localStorage.removeItem("nickname");
    window.localStorage.removeItem("pic");
    window.localStorage.removeItem("email");
}

/**
 * 获取用户名
 * @returns {string}
 */
export function getUsername() {
    return window.localStorage.getItem("username");
}

/**
 * 获取别名
 * @returns {string}
 */
export function getNickName() {
    return window.localStorage.getItem("nickname");
}

/**
 * 获取照片
 * @returns {string}
 */
export function getPic() {
    return window.localStorage.getItem("pic");
}

/**
 * 获取邮箱
 * @returns {string}
 */
export function getEmail() {
    return window.localStorage.getItem("email");
}

/**
 * 登录
 * @param access_token
 * @param userInfo
 */
export function login(access_token,userInfo) {
    setAccessToken(access_token);
    removeCaptchaToken();
    writeUserInfo(userInfo);
}

/**
 * 退出登录
 */
export function logout() {
    removeAccessToken();
    removeUserInfo();
}





